package com.ruoyi.file.client

import com.ruoyi.file.properties.AliAuthConfigProperties
import com.ruoyi.file.properties.AliOssConfigProperties
import com.aliyun.oss.OSS
import com.aliyun.oss.OSSClientBuilder
import com.aliyun.oss.common.auth.CredentialsProviderFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration

@Configuration
@EnableConfigurationProperties(AliAuthConfigProperties::class, AliOssConfigProperties::class)
class OssClientConfig {

    @Autowired
    private lateinit var aliAuthConfigProperties: AliAuthConfigProperties

    @Autowired
    private lateinit var aliOssConfigProperties: AliOssConfigProperties

    @Bean
    fun ossClient(): OSS = OSSClientBuilder().build(
        aliOssConfigProperties.endpoint,
        CredentialsProviderFactory.newDefaultCredentialProvider(
            aliAuthConfigProperties.accessKeyId,
            aliAuthConfigProperties.accessKeySecret
        )
    )

}